"""CopyRight(C) From WangShiheng"""
# Author: WangShiheng
# Package
from plugin.Fast_Use_Qt.interface.Page import Page
from util.base.Pool.base import BasePool

from PyQt5.QtWidgets import QFrame, QMainWindow, QGridLayout


class PagePool(BasePool):

    def __init__(self, InObj=Page):
        super().__init__(InObj)


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.Pages = PagePool()
        self.Inside_frame = QFrame(self)
        self.index_frame = QFrame(self)
        self.gridLayout = QGridLayout(self)

        self.Index_Layout = QGridLayout(self.index_frame)
        self.SetupUi()

    def SetupUi(self):
        # Init Box
        self.index_frame.setObjectName("indexFrame")
        self.Inside_frame.setObjectName("InsideFrame")
        self.gridLayout.setObjectName("MainGridLayout")
        # pack
        self.gridLayout.addWidget(self.pushButton, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.Inside_frame, 1, 0, 1, 1)

    def Begin_Ui(self):
        self.Index_Layout.setObjectName("IndexGridLayout")
        self._updateUi()
        self.Pages[0].reload_screen(self.Inside_frame)

    def _updateUi(self):
        for page in self.Pages:
            self.Index_Layout.addWidget(page.index_button, 0, self.Pages.pool.index(page), 1, 1)

    def registered(self, page):
        self.Pages.Add(page)
        self._updateUi()
